﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Teacher_TeacherInfo : System.Web.UI.Page
{
    DBClass dbobj = new DBClass();
    CommonClass ccobj = new CommonClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["UserID"].ToString() == null)
        {
            ccobj.MessageBox("你还没登录，请先登录！", "../Login.aspx");
        }
        if (!IsPostBack)
        {
            string strsql = "select * from Teacher where TeacherID='" + Session["UserID"].ToString().Trim() + "'";
            DataTable dt = dbobj.GetDataSet(strsql, "tabteacher");
            Label1.Text = dt.Rows[0]["TeacherID"].ToString();
            Label2.Text = dt.Rows[0]["TeacherName"].ToString();
            Label3.Text = dt.Rows[0]["Sex"].ToString();
            string strclass = dbobj.ExecScalar("select ClassName from Class where ClassID='" + dt.Rows[0]["ClassID"].ToString().Trim() + "'");
            Label4.Text = strclass;
            TextBox3.Text = dt.Rows[0]["Email"].ToString();
            TextBox4.Text = dt.Rows[0]["Phone"].ToString();
        }
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (TextBox1.Text.Trim() == "" && TextBox2.Text.Trim() == "" && TextBox3.Text.Trim() == "" && TextBox4.Text.Trim() == "")
            return;

        string strsql = "update Student set ";
        if (TextBox1.Text.Trim() != "" && TextBox2.Text.Trim() != "")
        {
            strsql += "PassWord='" + TextBox1.Text + "',";
        }
        if (TextBox3.Text.Trim() != "")
            strsql += "Email='" + TextBox3.Text + "',";
        if (TextBox4.Text.Trim() != "")
            strsql += "Phone='" + TextBox4.Text + "',";
        strsql = strsql.Substring(0, strsql.Length - 1);
        strsql += " where TeacherID='" + Session["UserID"].ToString().Trim() + "'";
        dbobj.ExecNonQuery(strsql);
        Response.Write(ccobj.MessageBox("更新成功！")); 
    }
}